clc 
close all
clear all
% This delay_smaples.mat file contains the following variables,
% These variables contain two columns, column 1: sender, column 2: mean delay
%
% delay_prks95  delay_prks90  delay_prks80  delay_prks70 
% delay_rid95  delay_rid90  delay_rid80  delay_rid70 
% delay_cmac95  delay_cmac90  delay_cmac80  delay_cmac70 
% I-ORDER is currently not included! 
% delay_csma 
% delay_rtscts 
% delay_scream 

load delay_samples.mat
delay_prks70 = delay_prks70(:,2);
delay_prks80 = delay_prks80(:,2);
delay_prks90 = delay_prks90(:,2);
delay_prks95 = delay_prks95(:,2);

delay_cmac70 = delay_cmac70(:,2);
delay_cmac80 = delay_cmac80(:,2);
delay_cmac90 = delay_cmac90(:,2);
delay_cmac95 = delay_cmac95(:,2);

delay_rid70 = delay_rid70(:,2);
delay_rid80 = delay_rid80(:,2);
delay_rid90 = delay_rid90(:,2);
delay_rid95 = delay_rid95(:,2);

delay_csma = delay_csma(:,2);
delay_rtscts = delay_rtscts(:,2);
delay_scream = delay_scream(:,2);

ALPHA=0.05;

MEAN = zeros(4,6);
Error_MEAN = zeros(4,6);
MEAN(1,1) = mean(delay_prks70);
MEAN(1,2) = mean(delay_csma);
MEAN(1,3) = mean(delay_rtscts);
MEAN(1,4) = mean(delay_rid70);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_prks70) / sqrt(size(delay_prks70, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_csma) / sqrt(size(delay_csma, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rtscts) / sqrt(size(delay_rtscts, 1));
Error_MEAN(1,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rid70) / sqrt(size(delay_rid70, 1));
MEAN(1,5) = mean(delay_cmac70);
Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_cmac70) / sqrt(size(delay_cmac70, 1));
MEAN(1,6) = mean(delay_scream);
Error_MEAN(1,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_scream) / sqrt(size(delay_scream, 1));
MEAN(2,1) = mean(delay_prks80);
MEAN(2,2) = mean(delay_csma);
MEAN(2,3) = mean(delay_rtscts);
MEAN(2,4) = mean(delay_rid80);

Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_prks80) / sqrt(size(delay_prks80, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_csma) / sqrt(size(delay_csma, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rtscts) / sqrt(size(delay_rtscts, 1));
Error_MEAN(2,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rid80) / sqrt(size(delay_rid80, 1));
MEAN(2,5) = mean(delay_cmac80);
Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_cmac80) / sqrt(size(delay_cmac80, 1));
MEAN(2,6) = mean(delay_scream);
Error_MEAN(2,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_scream) / sqrt(size(delay_scream, 1));
MEAN(3,1) = mean(delay_prks90);
MEAN(3,2) = mean(delay_csma);
MEAN(3,3) = mean(delay_rtscts);
MEAN(3,4) = mean(delay_rid90);

Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_prks90) / sqrt(size(delay_prks90, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_csma) / sqrt(size(delay_csma, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rtscts) / sqrt(size(delay_rtscts, 1));
Error_MEAN(3,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rid90) / sqrt(size(delay_rid90, 1));
MEAN(3,5) = mean(delay_cmac90);
Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_cmac90) / sqrt(size(delay_cmac90, 1));
MEAN(3,6) = mean(delay_scream);
Error_MEAN(3,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_scream) / sqrt(size(delay_scream, 1));
MEAN(4,1) = mean(delay_prks95);
MEAN(4,2) = mean(delay_csma);
MEAN(4,3) = mean(delay_rtscts);
MEAN(4,4) = mean(delay_rid95);

Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_prks95) / sqrt(size(delay_prks95, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_csma) / sqrt(size(delay_csma, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rtscts) / sqrt(size(delay_rtscts, 1));
Error_MEAN(4,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_rid95) / sqrt(size(delay_rid95, 1));
MEAN(4,5) = mean(delay_cmac95);
Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_cmac95) / sqrt(size(delay_cmac95, 1));
MEAN(4,6) = mean(delay_scream);
Error_MEAN(4,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(delay_scream) / sqrt(size(delay_scream, 1));

figure;
handle = barweb(MEAN, Error_MEAN,1, ['70%';'80%';'90%';'95%'], [], ['PDR requirement'], ['Mean delay'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS', 'RIDB','CMAC','SCREAM','orientation','horizontal');
set(gca,'fontsize',20);
set(gca,'YScale','log');
box on
maximize ();

[im_hatch, colorlist]=applyhatch_pluscolor(gcf, '/-\xkc',1,[1 1 1 1 0 1],[],[],5,10);


